<template>
  <div>
    <el-table :data="adminList" style="width: 100%"  v-loading="loading">
      <el-table-column prop="type.type_name" label="角色" width="180"></el-table-column>
      <el-table-column prop="account" label="账号" width="180"></el-table-column>
      <el-table-column prop="name" label="名字" width="180"></el-table-column>
      <el-table-column align="right">
        <!-- <template slot="header" slot-scope>
          <el-input v-model="userList" size="mini" placeholder="输入关键字搜索" />
        </template>-->
        <template slot-scope="scope" >
          <el-button
            id="btn-edit"
            icon="el-icon-edit"
            type="primary"
            @click="$router.push(`/admin/edit/${scope.row._id}`)"
          >编辑</el-button>
          <el-button
            icon="el-icon-delete"
            type="danger"
            @click="remove(scope.row)"
            style="margin:5px 3rem 0 10px"
          >&nbsp;删除</el-button>
        </template>
      </el-table-column>
    </el-table>
 
  </div>
</template>

<script>
export default {
  data() {
    return {
      adminList: [],
      loading: true
    };
  },
  mounted() {
    this.fetchAdmin();
  },
  methods: {
    //获得用户
    async fetchAdmin() {
      const admin_list = await this.$http.get("rest/admin_list");
      this.adminList = admin_list.data;
      this.loading = false;
    },
    //删除
    async remove(row) {
      this.$confirm(`是否删除?"${row.name}"`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(async () => {
        await this.$http.delete(`rest/admin/${row._id}`);
        this.$message({
          type: "success",
          message: "删除成功!"
        });
        this.fetchAdmin();
      });
    }
  }
};
</script>

<style lang="less">
.el-input--mini .el-input__inner {
  height: 38px !important;
}
</style>